package Buffer;

import java.io.*;

public class CopyFolderDemo {
    public static void main(String[] args) throws IOException {
        File srcFolder = new File("funCode\\src\\test");
        String srcFolderName = srcFolder.getName();
        // 输出地方
        File destFolder = new File("funCode\\src\\Things", srcFolderName);
        if (!destFolder.exists()) {
            destFolder.mkdir();
        }

        //获取文件数组
        File[] files = srcFolder.listFiles();
        for (File srcFile : files
        ) {
            String name = srcFile.getName();
            File destFile = new File(destFolder, name);

            copyFile(srcFile, destFile);
        }
    }

    private static void copyFile(File srcFile, File destFile) throws IOException {
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(srcFile));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(destFile));

        byte[] bytes = new byte[1024];
        int len;
        while ((len = bis.read(bytes)) != -1) {
            bos.write(bytes,0,len);
        }
        bis.close();
        bos.close();

    }
}
